CC = arm-linux-gcc
PREFIX = /usr/local/arm/3.4.1/arm-linux
INCPATH = -I$(PREFIX)/include -I./ -I../../include
LIBPATH = -L$(PREFIX)/lib -L../../lib
CFLAG = -Wall -g
DBG_CFLAG = -Wall -g -fPIC -shared
REL_CFLAG = -Wall -fPIC -shared
LDFLAG =
DBG_LDFLAG =
REL_LDFLAG =

TPATH = $(shell pwd)
BASENAME = $(notdir $(TPATH))
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
TARGET = lib$(BASENAME).so 
TEST_TARGET = $(BASENAME)_test

debug : $(OBJ)
	$(CC) $(DBG_CFLAG) $(DBG_LDFLAG) $(INCPATH) $(LIBPATH) -lpthread $(OBJ) -o $(TARGET)
	mv -f $(TARGET) ../../lib/.

release : $(OBJ)
	$(CC) $(REL_CFLAG) $(REL_LDFLAG) $(INCPATH) $(LIBPATH) -lpthread $(OBJ) -o $(TARGET)
	mv -f $(TARGET) ../../lib/.

test : $(OBJ)
	cd test
	$(CC) $(CFLAG) $(LDFLAG) $(INCPATH) $(LIBPATH) -lpthread -l$(BASENAME) ./test/$(BASENAME)_test.c -o $(TEST_TARGET)

%.o : %.c
	$(CC) $(CFLAG) -c $(INCPATH) $< -o $@

.PHONY : clean
clean:
	rm -f *.o $(TARGET) $(TEST_TARGET)
